﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Pong.Core.Entities;

namespace Pong.Core.Biz
{
    public class GameBiz : IBiz
    {
        public Engine Engine { get; set; }

        public Game Game { get; set; }

        public void Tick()
        {
        }

        public GameBiz Start(GameStartInfo startInfo)
        {
            Game = new Game();
            Game.PlayGround = new PlayGround { 
                Dimension = (startInfo.PlayGroundDimension.Width > 0 && startInfo.PlayGroundDimension.Height > 0)
                    ? startInfo.PlayGroundDimension : 
                    new Dimension {Width =  800, Height = 600 } };
            Game.MaxScore = startInfo.MaxScore > 0 ? startInfo.MaxScore : 20 ;
            Game.Balls = new List<Ball> { 
                new Ball { 
                    PlayGround = Game.PlayGround, 
                    Position = new Point { 
                        X = 400, 
                        Y = 300 } } };
            Game.Players = GeneratePlayers(startInfo);
            Game.Scores = GenerateScores(startInfo);
            return this;
        }

        private IDictionary<Player, int> GenerateScores(GameStartInfo startInfo)
        {
            var result = new Dictionary<Player, int>();
            return result;
        }

        private IList<Player> GeneratePlayers(GameStartInfo startInfo)
        {
            var result = new List<Player>();
            var playerCount = startInfo.PlayerNames != null ? startInfo.PlayerNames.Count : 0;

            return result;
            // TODO : Understand what was trying to be done here xD
            //if (startInfo.PlayerNames
        }

        public GameBiz Stop()
        {
            return this;
        }
    }

    public class GameStartInfo
    {
        public Dimension PlayGroundDimension { get; set; }
        public IList<string> PlayerNames { get; set; }
        public int MaxScore { get; set; }
        public int BallCount { get; set; }
    }
}
